Skip to content

feat(core): Pass normalizedRequest to the sampling context for root spans#21833

Merged
andreiborza merged 1 commit into
developfrom
ab/twp-standalone
Jun 29, 2026
Merged

feat(core): Pass normalizedRequest to the sampling context for root spans#21833
andreiborza merged 1 commit into
developfrom
ab/twp-standalone

Conversation

@andreiborza

@andreiborza andreiborza commented Jun 29, 2026

Copy link
Copy Markdown
Member

What

Forward the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans. _startRootSpan now includes it in the object passed to the sampler.

Why

SamplingContext already advertises a normalizedRequest field, and server SDKs already record the incoming request on the isolation scope, but core never wired the two together for root spans, so tracesSampler always received normalizedRequest: undefined on the standard root-span path. This closes that gap so custom samplers can decide based on the incoming request (drop health-check routes, raise the rate for /api/*, key off the HTTP method) instead of reverse-engineering it from the span name or attributes, which for an incoming HTTP root span may not yet carry the route at sampling time.

Extracted standalone from #21666 (the SentryTracerProvider stack): it has no dependency on that work, ships on its own merits, and shrinks #21666's review surface.

…pans

Forward the isolation scope's normalizedRequest into the tracesSampler
sampling context for root spans, so sampling functions can decide based on
the incoming request (url, method, query string).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.98 kB +0.03% +10 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 47.73 kB +0.03% +11 B 🔺
@sentry/browser (incl. Tracing, Profiling) 50.77 kB +0.02% +10 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.23 kB +0.02% +12 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.82 kB +0.02% +11 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 89.92 kB +0.02% +12 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 102.58 kB +0.02% +14 B 🔺
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.29 kB +0.02% +9 B 🔺
@sentry/vue 32.63 kB +0.04% +10 B 🔺
@sentry/vue (incl. Tracing) 47.84 kB +0.02% +9 B 🔺
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.9 kB +0.03% +12 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.25 kB +0.03% +11 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.41 kB +0.02% +14 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.69 kB +0.02% +16 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.2 kB +0.02% +15 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.46 kB +0.02% +14 B 🔺
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.1 kB +0.06% +75 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.07 kB +0.06% +75 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.12 kB +0.03% +75 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.08 kB +0.03% +75 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.82 kB +0.03% +75 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.77 kB +0.03% +75 B 🔺
@sentry/nextjs (client) 50.68 kB +0.02% +9 B 🔺
@sentry/sveltekit (client) 46.38 kB +0.03% +11 B 🔺
@sentry/core/server 77.55 kB +0.02% +10 B 🔺
@sentry/core/browser 63.89 kB +0.03% +14 B 🔺
@sentry/node-core 61.52 kB +0.02% +11 B 🔺
@sentry/node 123.5 kB +0.01% +8 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.42 kB +0.05% +21 B 🔺
@sentry/node - without tracing 73.62 kB +0.02% +8 B 🔺
@sentry/aws-serverless 84.41 kB +0.01% +8 B 🔺
@sentry/cloudflare (withSentry) - minified 180.38 kB +0.05% +75 B 🔺
@sentry/cloudflare (withSentry) 446.33 kB +0.03% +96 B 🔺

View base workflow run

@andreiborza andreiborza merged commit 128dacb into develop Jun 29, 2026
559 of 561 checks passed
@andreiborza andreiborza deleted the ab/twp-standalone branch June 29, 2026 09:41
sergical added a commit to getsentry/sentry-docs that referenced this pull request Jul 14, 2026
…10.65

The docs tracesSampler classifies traffic (AI agent / bot / user) to sample
accordingly and emit the docs.trace.sampled metric, but @sentry/core did not
pass normalizedRequest into the sampling context for root spans until 10.63.0
(getsentry/sentry-javascript#21833). On the previous 10.55.0 that field was
always undefined, so all traffic fell through to "unknown": AI-agent traces
were under-sampled, bot noise wasn't filtered, and the metric couldn't segment
traffic.

- Bump @sentry/nextjs and @sentry/browser to 10.65.0 (within the existing ^10
  range); consolidates the previously split @sentry/core versions.
- Consolidate classification into a single user-agent-based classifyFromHeaders,
  used by both the tracesSampler and a new span attribute.
- Tag every root span with docs.traffic_type so classification is queryable on
  spans, which flush from every environment (the metric only flushes reliably
  under sustained production traffic).
- Remove the middleware x-traffic-type/x-device-type request-header injection and
  the sampler's header-classification path: the injected headers never reached
  the sampler (middleware transactions sample off the incoming request; route
  handlers carry no normalized request), so that machinery was dead.

Co-Authored-By: Claude <noreply@anthropic.com>
sergical added a commit to getsentry/sentry-docs that referenced this pull request Jul 14, 2026
Fixes docs traffic classification. The tracesSampler reads
samplingContext.normalizedRequest to classify traffic (AI agent / bot / user)
and sample accordingly, but @sentry/core did not populate normalizedRequest in
the sampling context for root spans until 10.63.0
(getsentry/sentry-javascript#21833). On the previous 10.55.0 that field was
always undefined, so all traffic was classified "unknown": agent traces
under-sampled, bots not filtered, and docs.trace.sampled unable to segment.

No code changes needed — the existing sampler works once the SDK populates the
field. Also consolidates the previously split @sentry/core versions onto 10.65.

Co-Authored-By: Claude <noreply@anthropic.com>
sergical added a commit to getsentry/sentry-docs that referenced this pull request Jul 15, 2026
## DESCRIBE YOUR PR

Bumps `@sentry/nextjs` and `@sentry/browser` to `10.65.0` (within the
existing `^10` range) to fix docs traffic classification, which was
silently broken.

`src/tracesSampler.ts` reads `samplingContext.normalizedRequest` to
classify traffic as AI agent / bot / user and sample accordingly (agents
100%, bots 0%, users 30%), emitting the `docs.trace.sampled` metric. But
`@sentry/core` did not populate `normalizedRequest` in the sampling
context for root spans until **10.63.0**
([getsentry/sentry-javascript#21833](getsentry/sentry-javascript#21833)).
On the resolved `10.55.0` that field was always `undefined`, so all
traffic was classified `unknown`: agent traces were under-sampled, bot
noise wasn't filtered, and the metric couldn't segment traffic.

**No code changes** — the existing sampler works as designed once the
SDK populates the field. Verified on a preview deploy that `10.65.0`
populates the sampler's `normalizedRequest` (with the user-agent) on the
real Vercel runtime; the metric will show the correct
`ai_agent`/`bot`/`user` breakdown in production once deployed.

- Bump `@sentry/nextjs` + `@sentry/browser` to `^10.65.0`
- Consolidates the previously split `@sentry/core` versions onto
`10.65.0`

## IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants